﻿using EnumsNET;
using Kinlo.Entitys;
using Kinlo.MESDocking;
using LiveChartsCore;
using LiveChartsCore.Defaults;
using LiveChartsCore.Measure;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using NewLife.Data;
using NPOI.OpenXmlFormats.Vml.Office;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using UIWindows.Commands;
using UIWindows.GlobalStatics;
using UIWindows.Models;
using UIWindows.Models.Homes;
using UIWindows.Services;
using UIWindows.Tools.Helper;
using UIWindows.Views;
using XingLucifer.IBase.Enums;
using static log4net.Appender.RollingFileAppender;
using static NPOI.HSSF.Util.HSSFColor;
using static System.Resources.ResXFileRef;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace UIWindows.ViewModels
{
    public class HomePageViewModel : UIWindows.Domains.ViewModelBase, XingLucifer.IBase.IViewStatus
    {
        #region 配置显示项
        public GridView ShortCircuitView { get; set; }
        public GridView InsulationView { get; set; }
        public GridView BeforeWeightView { get; set; }
        public GridView ProductionDataView { get; set; }
        #endregion
        #region 注液统计
        public IEnumerable<ISeries> NG_MultiLiquidSeries { get; set; }
        public IEnumerable<ISeries> LiquidInjection_PassingRateSeries { get; set; }
        public IEnumerable<ISeries> NG_LessLiquidSeries { get; set; }
        #endregion

        #region 后称重
        public IEnumerable<ISeries> LiquidInjectionNGSeries { get; set; }
        public IEnumerable<ISeries> LeakDetectionNGSeries { get; set; }
        public IEnumerable<ISeries> AfterWeighingPassingRateSeries { get; set; }
        #endregion

        public GlobalStatics.ParameterStatic Parameter { get; set; }
        public GlobalStatics.HomeStatic Home { get; set; }
        public GlobalStatics.TemporaryStatic Temporary { get; set; }
        public SystemConfigStatic _configStatic { get; set; }
        public DisplayItemsStatic _displayItems { get; set; }
        public DeviceConfigStatic _deviceConfig { get; set; }

        private double _rLower;
        /// <summary>
        /// 电阻下限
        /// </summary>
        public double RLower
        {
            get { return _rLower; }
            set { SetProperty(ref _rLower, value); }
        }
        private double _rUpper;
        /// <summary>
        /// 电阻上限
        /// </summary>
        public double RUpper
        {
            get { return _rUpper; }
            set { SetProperty(ref _rUpper, value); }
        }
        public HomePageViewModel(GlobalStatics.ParameterStatic parameter, GlobalStatics.HomeStatic home, GlobalStatics.TemporaryStatic temporaryStatic, SystemConfigStatic configStatic, DisplayItemsStatic displayItems, DeviceConfigStatic deviceConfig)
        {
            Parameter = parameter;
            Home = home;
            ShortCircuitView = new GridView();
            InsulationView = new GridView();
            ProductionDataView = new GridView();
            BeforeWeightView = new GridView();
            _deviceConfig= deviceConfig;
            var model = _deviceConfig.RJ6901A.FirstOrDefault(x => x.IsBeingUsed);

            RLower = model.RLower;
            RUpper = model.RUpper;
            #region 注液统计
            home.ChartData.OV_MultiLiquid = new ObservableValue();
            home.ChartData.OV_LessLiquid = new ObservableValue();
            home.ChartData.OV_LiquidInjection_PassingRate = new ObservableValue();
            NG_MultiLiquidSeries = new GaugeBuilder().WithLabelsSize(18)
            .WithInnerRadius(45)
            .WithBackgroundInnerRadius(32).WithLabelFormatter((point) => $"{point.PrimaryValue:####}")
            .WithBackground(new SolidColorPaint(new SKColor(100, 181, 246, 90)))
            .WithLabelsPosition(PolarLabelsPosition.ChartCenter)
            .AddValue(home.ChartData.OV_MultiLiquid, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192)))
            .BuildSeries();

            NG_LessLiquidSeries = new GaugeBuilder().WithLabelsSize(18)
            .WithInnerRadius(45)
            .WithBackgroundInnerRadius(32).WithLabelFormatter((point) => $"{point.PrimaryValue:####}")
            .WithBackground(new SolidColorPaint(new SKColor(100, 181, 246, 90)))
            .WithLabelsPosition(PolarLabelsPosition.ChartCenter)
            .AddValue(home.ChartData.OV_LessLiquid, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192)))
            .BuildSeries();

            LiquidInjection_PassingRateSeries = new GaugeBuilder().WithLabelsSize(18)
            .WithInnerRadius(60)
            .WithBackgroundInnerRadius(42).WithLabelFormatter((point) => $"{point.PrimaryValue:P2}")
            .WithBackground(new SolidColorPaint(new SKColor(100, 181, 246, 90)))
            .WithLabelsPosition(PolarLabelsPosition.ChartCenter)
            .AddValue(home.ChartData.OV_LiquidInjection_PassingRate, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192)))
            .BuildSeries();

            home.ChartData.OV_LiquidInjection_PassingRate.Value = 0;
            #endregion

            #region 后称重
            home.ChartData.OV_LiquidInjection = new ObservableValue();
            home.ChartData.OV_LeakDetection = new ObservableValue();
            home.ChartData.OV_AfterWeighingPassingRate = new ObservableValue();
            LiquidInjectionNGSeries = new GaugeBuilder()
            {
                LabelsSize = 0,
                InnerRadius = 36,
                BackgroundInnerRadius = 25,
                Background = new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(100, 181, 246, 90)),
            }.AddValue(home.ChartData.OV_LiquidInjection, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192))).BuildSeries();

            LeakDetectionNGSeries = new GaugeBuilder()
            {
                LabelsSize = 0,
                InnerRadius = 36,
                BackgroundInnerRadius = 25,
                Background = new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(100, 181, 246, 90))
            }.AddValue(home.ChartData.OV_LeakDetection, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192))).BuildSeries();

            AfterWeighingPassingRateSeries = new GaugeBuilder()
            {
                LabelsSize = 0,
                InnerRadius = 36,
                BackgroundInnerRadius = 25,
                Background = new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(100, 181, 246, 90))
            }.AddValue(home.ChartData.OV_AfterWeighingPassingRate, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192))).BuildSeries();
            #endregion

            Temporary = temporaryStatic;
            _configStatic = configStatic;
            #region 前稳重显示
            SetDisplayItemsBeforeWeight();
            SetShowBeforWeight();
            #endregion

            #region 短路测试仪显示配置
            SetDisplayItemsShortCicute();
            SetShowShortCicute();
            #endregion
            #region 绝缘测试显示配置
            SetDisplayItemsInsulation();
            SetShowInsulation();
            #endregion
        }

      
        public DelegateCommand ClockOutline => new DelegateCommand(() =>
        {

        });

        private List<DisplayItemsModel> _displayItems_ShortCircuit;
        private List<DisplayItemsModel> _displayItems_Insulation;
        private List<DisplayItemsModel> _displayItems_BeforeWeight;

        public void Load()
        {
            if (_displayItems == null)
            {
                _displayItems = Domains.ObjectContainer.ResolveSingleton<DisplayItemsStatic>();
            }
            if (!_displayItems.IsHomeUpdate)
            {
                return;
            }
            _displayItems.IsHomeUpdate = false;
            ProductionDataView.Columns.Clear();
            List<DisplayItemsModel> list = new List<DisplayItemsModel>(_displayItems.WeighingDisplayItems);
            list.Sort((x, y) => x.CompareTo(y));
            foreach (var item in list)
            {
                if (item.IsDisplay)
                {
                    GridViewColumn gvc = new GridViewColumn { Header = item.Description };
                    if (item.DataType == "结果")
                    {
                        FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
                        border.SetValue(Border.CornerRadiusProperty, new CornerRadius(3));
                        border.SetBinding(Border.BackgroundProperty, new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            Converter = new Tools.Converter.ResultToColorConverter()
                        });

                        FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                        text.SetValue(TextBlock.MarginProperty, new Thickness(5, 3, 5, 3));
                        text.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Colors.White));
                        text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                        text.SetBinding(TextBlock.TextProperty, new Binding { Path = new System.Windows.PropertyPath(item.Name) });

                        border.AppendChild(text);
                        var dataTemplate = new DataTemplate();
                        dataTemplate.VisualTree = border;
                        gvc.CellTemplate = dataTemplate;
                    }
                    else if (item.DataType == "浮点型")
                        gvc.DisplayMemberBinding = new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            StringFormat = "F2"
                        };
                    else if (item.DataType == "时间型")
                        gvc.DisplayMemberBinding = new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            StringFormat = "yyyy-MM-dd HH:mm:ss",
                            Converter = new Tools.Converter.TimeStampToDateTimeStringConverter()
                        };
                    else
                        gvc.DisplayMemberBinding = new Binding { Path = new System.Windows.PropertyPath(item.Name) };
                    ProductionDataView.Columns.Add(gvc);
                }
            }
        }

        public void UnLoad()
        {

        }
        void SetDisplayItemsShortCicute()
        {
            var temp = new MessageShortCircuitModel();
            _displayItems_ShortCircuit = new List<DisplayItemsModel>()
            {
                new DisplayItemsModel(){
                    Index = 1,
                    DataType = "结果",
                    Description = "总结果",
                    Name = nameof(temp.Result) ,//这个双向绑定的属性
                    SqlName = "ALL",//用来区分是什么设备
                },
                new DisplayItemsModel(){
                    Index = 2,
                    Description = "位 置",
                    Name = "Location",
                    SqlName = "ALL",
                },
                new DisplayItemsModel(){
                    Index = 3,
                    Description = "条 码",
                    Name = "BarCode",
                    SqlName = "ALL",
                },
                new DisplayItemsModel(){
                    Index = 16,
                    Description = "电阻测试时间",
                    Name =nameof(temp.TestTime),
                    SqlName = "ALL",
                },
                new DisplayItemsModel(){
                    Index = 17,
                    DataType = "浮点型",
                    Description = "电流测试数据",
                    Name =nameof(temp.ShortCircuitElectricCurrent),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 18,
                    DataType = "浮点型",
                    Description = "电阻测试数据",
                    Name =nameof(temp.ShortCircuitResistance),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 19,
                    DataType = "浮点型",
                    Description = "电压测试数据",
                    Name =nameof(temp.ShortCircuitVoltage),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 20,
                    DataType = "浮点型",
                    Description = " 阻值上限值",
                    Name =nameof(temp.ShortCircuitResistanceUp),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 21,
                    DataType = "浮点型",
                    Description = " 阻值下限值",
                    Name =nameof(temp.ShortCircuitResistanceDown),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                
                new DisplayItemsModel(){
                    Index = 22,
                    DataType = "浮点型",
                    Description = "测试时长(S)",
                    Name =nameof(temp.ShortCircuitTestTime),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                
                new DisplayItemsModel(){
                    Index = 23,
                    DataType = "浮点型",
                    Description = "测试剩余时长(S)",
                    Name =nameof(temp.ShortCicuteResidueTime),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },



            };

        }
        void SetShowShortCicute()
        {

            foreach (var item in _displayItems_ShortCircuit)
            {
                if (item.SqlName == _configStatic.SCM.ShortCircuit.ToString() || item.SqlName == "ALL")
                {
                    GridViewColumn gvc = new GridViewColumn { Header = item.Description };
                    if (item.DataType == "结果")
                    {
                        FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
                        border.SetValue(Border.CornerRadiusProperty, new CornerRadius(3));
                        border.SetBinding(Border.BackgroundProperty, new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            Converter = new Tools.Converter.ResultToColorConverter()
                        });

                        FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                        text.SetValue(TextBlock.MarginProperty, new Thickness(5, 3, 5, 3));
                        text.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Colors.White));
                        text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                        text.SetBinding(TextBlock.TextProperty, new Binding { Path = new System.Windows.PropertyPath(item.Name) });

                        border.AppendChild(text);
                        var dataTemplate = new DataTemplate();
                        dataTemplate.VisualTree = border;
                        gvc.CellTemplate = dataTemplate;
                    }
                    else if (item.DataType == "浮点型")
                        gvc.DisplayMemberBinding = new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            StringFormat = "F2"
                        };
                    else if (item.DataType == "时间型")
                        gvc.DisplayMemberBinding = new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            StringFormat = "yyyy-MM-dd HH:mm:ss",
                            Converter = new Tools.Converter.TimeStampToDateTimeStringConverter()
                        };
                    else
                        gvc.DisplayMemberBinding = new Binding { Path = new System.Windows.PropertyPath(item.Name) };

                    ShortCircuitView.Columns.Add(gvc);
                }
            }
        }
        void SetDisplayItemsInsulation()
        {
            var temp = new MessageShortCircuitModel();
            _displayItems_Insulation = new List<DisplayItemsModel>()
            {
                new DisplayItemsModel(){
                    Index = 1,
                    DataType = "结果",
                    Description = "总结果",
                    Name = nameof(temp.Result) ,//这个双向绑定的属性
                    SqlName = "ALL",//用来区分是什么设备
                },
                new DisplayItemsModel(){
                    Index = 2,
                    Description = "位 置",
                    Name = "Location",
                    SqlName = "ALL",
                },
                new DisplayItemsModel(){
                    Index = 3,
                    Description = "条 码",
                    Name = "BarCode",
                    SqlName = "ALL",
                },
                new DisplayItemsModel(){
                    Index = 16,
                    Description = "电阻测试时间",
                    Name =nameof(temp.TestTime),
                    SqlName = "ALL",
                },
                new DisplayItemsModel(){
                    Index = 17,
                    DataType = "浮点型",
                    Description = "电流测试数据",
                    Name =nameof(temp.ShortCircuitElectricCurrent),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 18,
                    DataType = "浮点型",
                    Description = "电阻测试数据",
                    Name =nameof(temp.ShortCircuitResistance),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 19,
                    DataType = "浮点型",
                    Description = "电压测试数据",
                    Name =nameof(temp.ShortCircuitVoltage),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 20,
                    DataType = "浮点型",
                    Description = " 阻值上限值",
                    Name =nameof(temp.ShortCircuitResistanceUp),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 21,
                    DataType = "浮点型",
                    Description = " 阻值下限值",
                    Name =nameof(temp.ShortCircuitResistanceDown),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                
                new DisplayItemsModel(){
                    Index = 22,
                    DataType = "浮点型",
                    Description = "测试时长(S)",
                    Name =nameof(temp.ShortCircuitTestTime),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                
                new DisplayItemsModel(){
                    Index = 23,
                    DataType = "浮点型",
                    Description = "测试剩余时长(S)",
                    Name =nameof(temp.ShortCicuteResidueTime),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },



            };

        }
        void SetShowInsulation()
        {

            foreach (var item in _displayItems_Insulation)
            {
                if (item.SqlName == _configStatic.SCM.ShortCircuit.ToString() || item.SqlName == "ALL")
                {
                    GridViewColumn gvc = new GridViewColumn { Header = item.Description };
                    if (item.DataType == "结果")
                    {
                        FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
                        border.SetValue(Border.CornerRadiusProperty, new CornerRadius(3));
                        border.SetBinding(Border.BackgroundProperty, new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            Converter = new Tools.Converter.ResultToColorConverter()
                        });

                        FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                        text.SetValue(TextBlock.MarginProperty, new Thickness(5, 3, 5, 3));
                        text.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Colors.White));
                        text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                        text.SetBinding(TextBlock.TextProperty, new Binding { Path = new System.Windows.PropertyPath(item.Name) });

                        border.AppendChild(text);
                        var dataTemplate = new DataTemplate();
                        dataTemplate.VisualTree = border;
                        gvc.CellTemplate = dataTemplate;
                    }
                    else if (item.DataType == "浮点型")
                        gvc.DisplayMemberBinding = new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            StringFormat = "F2"
                        };
                    else if (item.DataType == "时间型")
                        gvc.DisplayMemberBinding = new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            StringFormat = "yyyy-MM-dd HH:mm:ss",
                            Converter = new Tools.Converter.TimeStampToDateTimeStringConverter()
                        };
                    else
                        gvc.DisplayMemberBinding = new Binding { Path = new System.Windows.PropertyPath(item.Name) };

                    InsulationView.Columns.Add(gvc);
                }
            }
        }

        void SetDisplayItemsBeforeWeight()
        {
            var temp = new MessageBeforeWeighingModel();
            if (_configStatic.SCM.MainDeviceType == MainDeviceTypeEnum.一次注液)
            {
                _displayItems_BeforeWeight = new List<DisplayItemsModel>
                 {
                         new DisplayItemsModel()
                         {
                             Index = 1,
                             DataType = "结果",
                             Description = "结 果",
                             Name =nameof(temp.Result),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 2,
                             Description = "条 码",
                             Name =nameof(temp.BarCode),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 3,
                             //DataType = "时间型",
                             Description = "前称时间",
                             Name =nameof(temp.Time),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 4,
                             DataType = "浮点型",
                             Description = "前称重量",
                             Name =nameof(temp.FormerWeighing),//这个双向绑定的属性 
                         },
                          new DisplayItemsModel()
                         {
                             Index = 5,
                             Description = "前称重位置",
                             Name =nameof(temp.LocationFormerWeighing),//这个双向绑定的属性 
                         },
                 };
            }
            else
            {
                _displayItems_BeforeWeight = new List<DisplayItemsModel>
                 {
                         new DisplayItemsModel()
                         {
                             Index = 1,
                             DataType = "结果",
                             Description = "结 果",
                             Name =nameof(temp.Result),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 2,
                             Description = "条 码",
                             Name =nameof(temp.BarCode),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 3,
                            // DataType = "时间型",
                             Description = "前称时间",
                             Name =nameof(temp.Time),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 4,
                              DataType = "浮点型",
                             Description = "前称重量",
                             Name =nameof(temp.FormerWeighing),//这个双向绑定的属性 
                         },
                          new DisplayItemsModel()
                         {
                             Index = 5,
                             Description = "前称重位置",
                             Name =nameof(temp.LocationFormerWeighing),//这个双向绑定的属性 
                         },
                           new DisplayItemsModel()
                         {
                             Index = 8,
                              DataType = "浮点型",
                             Description = "目标注液量",
                             Name =nameof(temp.TargetInjectionVolume),//这个双向绑定的属性 
                         },
                            new DisplayItemsModel()
                         {
                             Index = 8,
                              DataType = "浮点型",
                             Description = "化成失液量",
                             Name =nameof(temp.LossAfterFormation),//这个双向绑定的属性 
                         },
                            new DisplayItemsModel()
                         {
                             Index = 7,
                              DataType = "浮点型",
                             Description = "电池干重",
                             Name =nameof(temp.NetWeight),//这个双向绑定的属性 
                         },
                             new DisplayItemsModel()
                         {
                             Index = 8,
                              DataType = "浮点型",
                             Description = "一注后称重",
                             Name =nameof(temp.OneAfterWeighing),//这个双向绑定的属性 
                         },
                 };
            }
        }

        public DelegateCommand ClickMe => new DelegateCommand(() =>
        {
            MySqlHelper mySqlHelper = new MySqlHelper(Parameter.MESParameter.OthenDatabaseurl);
            var oneData = mySqlHelper.GetBatteryByCode("Empty83564123456789024720");
            if (oneData.status)
            {
                var NetWeight = oneData.netWeight;
                var OneAfterWeighing = oneData.outputWeight;
            }
        });
        void SetShowBeforWeight()
        {
            foreach (var item in _displayItems_BeforeWeight)
            {
                GridViewColumn gvc = new GridViewColumn { Header = item.Description };
                if (item.DataType == "结果")
                {
                    FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
                    border.SetValue(Border.CornerRadiusProperty, new CornerRadius(3));
                    border.SetBinding(Border.BackgroundProperty, new Binding
                    {
                        Path = new System.Windows.PropertyPath(item.Name),
                        Converter = new Tools.Converter.ResultToColorConverter()
                    });

                    FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                    text.SetValue(TextBlock.MarginProperty, new Thickness(5, 3, 5, 3));
                    text.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Colors.White));
                    text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                    text.SetBinding(TextBlock.TextProperty, new Binding { Path = new System.Windows.PropertyPath(item.Name) });

                    border.AppendChild(text);
                    var dataTemplate = new DataTemplate();
                    dataTemplate.VisualTree = border;
                    gvc.CellTemplate = dataTemplate;
                }
                else if (item.DataType == "浮点型")
                    gvc.DisplayMemberBinding = new Binding
                    {
                        Path = new System.Windows.PropertyPath(item.Name),
                        StringFormat = "F2"
                    };
                else if (item.DataType == "时间型")
                    gvc.DisplayMemberBinding = new Binding
                    {
                        Path = new System.Windows.PropertyPath(item.Name),
                        StringFormat = "yyyy-MM-dd HH:mm:ss",
                        Converter = new Tools.Converter.TimeStampToDateTimeStringConverter()
                    };
                else
                    gvc.DisplayMemberBinding = new Binding { Path = new System.Windows.PropertyPath(item.Name) };

                BeforeWeightView.Columns.Add(gvc);
            }


        }
        public DelegateCommand TestCMD => new DelegateCommand(() =>
        {
            int b = 239;
            double c = (double)b /240;
            double a = Math.Round(c, 4, MidpointRounding.ToNegativeInfinity) ;
            a = a * 100;
            $"{a}".MessageDialogs(MessageLevelType.信息, false, Enums.PopUpTypes.Global);
        });
    }

   
}
